package com.zmn.oms.admin.thymeleaf;

import com.alibaba.fastjson.JSON;
import com.zmn.common.utils.math.MathUtil;
import com.zmn.common.utils.math.MoneyUtil;
import com.zmn.common.utils.string.StringUtil;
import com.zmn.consts.GlobalConsts;
import com.zmn.mcc.cas.model.LoginStaff;
import com.zmn.mcc.cas.web.StaffAdminService;
import com.zmn.oms.admin.common.BaiduAk;
import com.zmn.oms.admin.common.BaiduAkUtil;
import com.zmn.oms.common.constant.OrderPayConsts;
import com.zmn.oms.common.constant.OrderPremissionConsts;
import com.zmn.oms.common.utils.BaiduMapUtil;
import com.zmn.oms.common.utils.MobileUtil;
import org.apache.commons.lang3.StringUtils;
import org.thymeleaf.context.IExpressionContext;
import org.thymeleaf.expression.IExpressionObjectFactory;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

/**
 * 类描述: 工具类扩展
 *
 * @author liuying
 * @date 2019/01/08 7:57 PM
 */
public class ZmnExpressionFactory implements IExpressionObjectFactory {

    private static final Map<String, Object> ALL_EXPRESSION_OBJECT;

    static {
        final Map<String, Object> allExpressionObjectNames = new LinkedHashMap<>();
        allExpressionObjectNames.put("stringUtils", new StringUtils());
        allExpressionObjectNames.put("moneyUtil", new MoneyUtil());
        allExpressionObjectNames.put("stringUtil", new StringUtil());
        allExpressionObjectNames.put("mobileUtil", MobileUtil.class);
        allExpressionObjectNames.put("mathUtil", new MathUtil());
        allExpressionObjectNames.put("jsons", JSON.class);
        allExpressionObjectNames.put("globalConsts", GlobalConsts.class);
        allExpressionObjectNames.put("orderPayConsts", OrderPayConsts.class);
        allExpressionObjectNames.put("orderPremissionConsts", OrderPremissionConsts.class);
        allExpressionObjectNames.put("orderAuthPermit", OrderAuthPermit.getInstance());
        allExpressionObjectNames.put("partMathUtil", new com.zmn.oms.common.utils.MathUtil());
        allExpressionObjectNames.put("baiduMapUtil", new BaiduAk());
        allExpressionObjectNames.put("baiduAkUtil", BaiduAkUtil.class);
        //allExpressionObjectNames.put("currentStaff", StaffAdminService.class);
        ALL_EXPRESSION_OBJECT = Collections.unmodifiableMap(allExpressionObjectNames);
    }

    public ZmnExpressionFactory() {
        super();
    }

    @Override
    public Set<String> getAllExpressionObjectNames() {
        return ALL_EXPRESSION_OBJECT.keySet();
    }

    @Override
    public Object buildObject(IExpressionContext context, String expressionObjectName) {
        if (expressionObjectName == null) {
            return null;
        }
        return ALL_EXPRESSION_OBJECT.get(expressionObjectName);
    }

    @Override
    public boolean isCacheable(String expressionObjectName) {
        return expressionObjectName != null && ALL_EXPRESSION_OBJECT.containsKey(expressionObjectName);
    }

    public static void main(String[] args) {
        System.out.println(StringUtils.class.getSimpleName());
    }
}
